package com.example.book.model;

import com.bit.book.enums.ResultCode;
import lombok.Data;

@Data
public class Result<T> {
    private ResultCode code; //200-成功   -1 未登录  -2 异常....
    private String errMsg;
    private T data;

    public static <T> Result<T> success(T data){
        Result result = new Result<>();
        result.setCode(ResultCode.SUCCESS);
        result.setData(data);
        return result;
    }

    public static <T> Result<T> fail(String errMsg){
        Result result = new Result<>();
        result.setCode(ResultCode.FAIL);
        result.setErrMsg(errMsg);
        return result;
    }

    public static <T> Result<T> unlogin(){
        Result result = new Result<>();
        result.setCode(ResultCode.UNLOGIN);
        result.setErrMsg("用户未登录");
        return result;
    }

    public static <T> Result<T> unlogin(T data){
        Result result = new Result<>();
        result.setCode(ResultCode.UNLOGIN);
        result.setErrMsg("用户未登录");
        result.setData(data);
        return result;
    }
}
